home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Harmless / Eyecon / Source / EyeView.m < prev    next >
Encoding:
Text File  |  1994-04-01  |  2.1 KB  |  80 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. #import "EyeView.h"
  5. #import "eye.h"
  6. #import <math.h>
  7. #import <dpsclient/dpsclient.h>
  8. #import <dpsclient/psops.h>
  9.  
  10. #define MAX_BALL_RAD    9.0
  11. #define PUPIL_RAD    2.0
  12. #define GAP        3.0
  13.  
  14. int square(int x)
  15. {
  16.     return (x * x);
  17. }
  18.  
  19. @implementation EyeView
  20.  
  21. + newFrame:(const NXRect *) frm;
  22. {
  23.     [(self = [super newFrame:frm]) allocateGState];
  24.     return self;
  25. }
  26.  
  27. -init
  28. {
  29.     leftCenter.x  = bounds.size.width / 4;
  30.     rightCenter.x = bounds.size.width * 3 / 4;
  31.     leftCenter.y = rightCenter.y = bounds.size.height / 2;
  32.  
  33.     // draw the eye background
  34.     [self lockFocus];
  35.     PSsetgray(NX_LTGRAY);
  36.     PSrectfill(0.0, 0.0, bounds.size.width, bounds.size.height);
  37.     PSsetgray(0.0);
  38.     PSsetlinewidth(2);
  39.     PSarc(leftCenter.x, leftCenter.y, MAX_BALL_RAD + PUPIL_RAD + GAP, 0.0, 360.0);
  40.     PSstroke();
  41.     PSarc(rightCenter.x, rightCenter.y, MAX_BALL_RAD + PUPIL_RAD + GAP, 0.0, 360.0);
  42.     PSstroke();
  43.     [self unlockFocus];
  44.     [window flushWindow];
  45.     NXPing();
  46. }
  47.  
  48. - drawBalls
  49. {
  50.     mouseTemp = mouseLoc;
  51.     [window getMouseLocation: &mouseLoc];
  52.     [self convertPoint: &mouseLoc fromView: nil];
  53.     if (mouseLoc.x == mouseTemp.x && mouseLoc.y == mouseTemp.y) return;
  54.  
  55.     mag = sqrt(square(mouseLoc.x - leftCenter.x) + square(mouseLoc.y - leftCenter.y));
  56.     if (mag < MAX_BALL_RAD) {
  57.         leftBall.x = mouseLoc.x;
  58.         leftBall.y = mouseLoc.y;
  59.     } else {
  60.         leftBall.x = MAX_BALL_RAD * (mouseLoc.x - leftCenter.x) / mag + leftCenter.x ;
  61.         leftBall.y = MAX_BALL_RAD * (mouseLoc.y - leftCenter.y) / mag + leftCenter.y ;
  62.     }
  63.     mag = sqrt(square(mouseLoc.x - rightCenter.x) + square(mouseLoc.y - rightCenter.y));
  64.     if (mag < MAX_BALL_RAD) {
  65.         rightBall.x = mouseLoc.x;
  66.         rightBall.y = mouseLoc.y;
  67.     } else {
  68.         rightBall.x = MAX_BALL_RAD * (mouseLoc.x - rightCenter.x) / mag + rightCenter.x;
  69.         rightBall.y = MAX_BALL_RAD * (mouseLoc.y - rightCenter.y) / mag + rightCenter.y;
  70.     }
  71.     
  72.     [self lockFocus];
  73.     eyeball(leftCenter.x, leftCenter.y, rightCenter.x, rightCenter.y, leftBall.x, leftBall.y, rightBall.x, rightBall.y, MAX_BALL_RAD, PUPIL_RAD, GAP);
  74.     [window flushWindow];
  75.     [self unlockFocus];
  76.     NXPing();
  77. }
  78.  
  79. @end
  80.